package track2.data;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;

import track2.context.Config;

public class QueryToken {

	private static QueryToken _instance = null;
	private Map<Integer, String> map = null;

	private QueryToken() {
		map = new HashMap<Integer, String>();
		_init();
	}

	/**
	 * initial map based on the file
	 */
	private void _init() {
		try {
			System.out.println("Loading Query Token...");
			BufferedReader br = new BufferedReader(new FileReader(
					Config.queryTokenPath));
			String line;
			while ((line = br.readLine()) != null) {
				String[] paras = line.split("\t");// id seg1|seg2|seg3....
				map.put(Integer.parseInt(paras[0]), paras[1]);
			}
			br.close();
			System.out.println("Loading Query Token finished...");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static synchronized QueryToken getInstance() {
		if (_instance == null) {
			_instance = new QueryToken();
		}
		return _instance;
	}

	public Map<Integer, String> getMap() {
		return map;
	}
}
